package com.acaslless.datasource.config;

import com.acaslless.datasource.handler.MybatisDefaultDBFieldHandler;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * mybatis配置
 *
 * @author haohan
 * @date 2025/3/28 14:19
 **/
@Slf4j
@Configuration
public class MybatisConfiguration {

    /**
     * 插件注册
     * */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        // 插件注册
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); // 分页插件
//        interceptor.addInnerInterceptor(new CustomDataPermissionInterceptor()); // 数据权限处理器
        log.info("============= mybatis-plus插件注册 配置成功 =============");
        return interceptor;
    }

    /**
     * 字段填充注入
     * */
    @Bean
    public MetaObjectHandler mybatisDefaultDBFieldHandler() {
        return new MybatisDefaultDBFieldHandler();
    }
}
